import { Behaviour, RenderableBehaviour, getGameObjectById, Transform, SerilizeField, propertyEditor_Number } from "../gameengine";
import { ColliderSystem } from "./ColliderSystem";



export enum RectColliderType {
    NONE = 0,
    MAINROLE = 1,
    WALL = 2,
    ENEMY = 3,
    TP = 4,
    ITEM = 5,
    SHOP = 6
}

export class RectCollider extends RenderableBehaviour {


    @SerilizeField(propertyEditor_Number)
    public type: number = 0;

    @SerilizeField(propertyEditor_Number)
    public width: number = 0;

    @SerilizeField(propertyEditor_Number)
    public height: number = 0;


    public onColliderStart: Function;

    protected onStart() {
        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
        colliderSystem.addRectCollider(this);
        this.displayObject.renderNode = this;
        console.log(this.displayObject.id)
     
    }

     onEnd() {
        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
        colliderSystem.removeRectCollider(this);
        console.log('1234')
    }

    protected onUpdate(advancedTime: number) {
    }

    get left() {
        const transform = this.displayObject.getScript(Transform);
        return transform.globalMatrix.tx;
    }

    get top() {
        const transform = this.displayObject.getScript(Transform);
        return transform.globalMatrix.ty;
    }

    get right() {
        return this.left + this.width;
    }

    get bottom() {
        return this.top + this.height;
    }

    onRender(context: CanvasRenderingContext2D) {
        context.save();
        context.strokeRect(0, 0, this.width, this.height);
        context.restore();
    }


}